<!DOCTYPE html>

<html class="no-js">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <script src="https://cdn.staticfile.org/axios/0.19.0-beta.1/axios.js"></script>
  <script src="https://cdn.staticfile.org/vue/2.5.17/vue.js"></script>
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.13.0/theme-chalk/index.css" />
  <script src="https://cdn.staticfile.org/element-ui/2.13.0/index.js"></script>
  <link rel="stylesheet" href="https://cdn.staticfile.org/animate.css/3.7.0/animate.min.css" />
  <link rel="stylesheet" href="../../../lib/index.css" />
  <script src="../../../lib/avue.js"></script>
</head>

<body>
  <div id="app">
    <p>
      <el-button @click="copy">直接复制</el-button>
      <el-button @click="textarea=''">清 空</el-button>
    </p>
    <el-input placeholder="内容" v-model="text">
      <template slot="append">
        <el-button @click="copyText" color="primary">复制</el-button>
      </template>
    </el-input>
    <div style="margin-top:10px">
      <el-input type="textarea" v-model="textarea" cols="40" rows="3"></el-input>
    </div>
  </div>
</body>
<script>
  new Vue({
    el: '#app',
    data() {
      return {
        text: '',
        textarea: ''
      }
    },
    methods: {
      copyText() {
        this.$Clipboard({
          text: this.text
        }).then(() => {
          this.$message.success('复制成功')
        }).catch(() => {
          this.$message.error('复制失败')
        });
      },
      copy() {
        this.$Clipboard({
          text: '测试==复制至剪切板的文本==测试'
        }).then(() => {
          this.$message.success('复制成功')
        }).catch(() => {
          this.$message.error('复制失败')
        });
      }
    }
  })
</script>

</html>